package com.steakliu.sun.client.spring;

import com.steakliu.sun.client.SunClient;
import com.steakliu.sun.client.api.ClientConfig;
import org.springframework.beans.factory.FactoryBean;

/**
 * 功能说明： 使用FactoryBean注册SunClient Bean
 * <p>
 * Original @Author: steakliu-刘牌, 2023-01-13  23:23
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
public class SunFactoryBean implements FactoryBean<Object> {

    private Class<?> interfaceClass;

    private Class<?> fallbackClass;

    private ClientConfig clientConfig;

    private Object object;

    public void init() throws Exception {
        clientConfig.setFallbackClass(fallbackClass);
        SunClient sunClient = new SunClient(clientConfig);
        this.object = sunClient.create(interfaceClass);
    }

    @Override
    public Object getObject() {
       return object;
    }

    @Override
    public Class<?> getObjectType() {
        return interfaceClass;
    }

    public Class<?> getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class<?> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    public ClientConfig getClientConfig() {
        return clientConfig;
    }

    public void setClientConfig(ClientConfig clientConfig) {
        this.clientConfig = clientConfig;
    }

    public Class<?> getFallbackClass() {
        return fallbackClass;
    }

    public void setFallbackClass(Class<?> fallbackClass) {
        this.fallbackClass = fallbackClass;
    }
}
